<?php
define('Acan_Afun_js',1);
	function Afun_js_echo($str){
		echo '<script>'.$str.'</script>';
	}
/*js提示 + 跳转*/
	function Afun_alert($val=""){
		header('Content-type: text/html; charset=UTF-8');
		echo '<script>alert("'.$val.'");</script>';
	}
	function Afun_refresh($val="",$url="",$timeout='1'){
		header('Content-type: text/html; charset=UTF-8');
		if(!empty($val)){
			echo '<script>alert("'.$val.'");</script>';
		}
		if(!empty($url)){
			if($url == 'referrer'){
				echo '<script>setTimeout(function(){location.href=document.referrer;},'.$timeout.')</script>';
			}else{
				echo '<script>setTimeout(function(){location.href="'.$url.'";},'.$timeout.')</script>';
			}
		}else{
			echo '<script>setTimeout(function(){window.location.reload();},'.$timeout.')</script>';
		}
	}
/*新窗口打开*/
	function Afun_js_open($url,$name='',$str=''){
		echo '<script>window.open(\''.$url.'\',\''.$name.'\',\''.$str.'\');</script>';
	}
	function Afun_json_encode($obj) {
		if(is_int($obj) || is_float($obj)){
			$json = $obj;
		}else if(is_bool($obj)){
			if($obj==false){
				$json = 'false';
			}else{
				$json = 'true';
			}
		}else if($obj==null){
			$json = "null";
		}else if(is_string($obj)){
			$json = "\"".str_replace(array("\\","\"","\r","\n","\t"),array("\\\\","\\\"","\\r","\\n","\\t"),$obj)."\"";
		}else if(is_array($obj) || is_object($obj)){
			$i = 0;
			foreach ($obj as $key => $val) {
				if(is_int($key) && $key === $i){}else{$type= 'obj';}	$i++;
			}
			if($type == 'obj')
				foreach ($obj as $key => $val) {
					if(empty($json))
						$json = "\"$key\"".':'.Afun_json_encode($val);
					else
						$json .= ",\"$key\"".':'.Afun_json_encode($val);
				}
			else
				foreach ($obj as $val) {
					if(empty($json))
						$json = Afun_json_encode($val);
					else
						$json .= ",".Afun_json_encode($val);
				}
			$json = $type == 'obj' ? "{".$json."}" : "[".$json."]";
		}
		return $json;
	}
if(!function_exists('json_encode')){
	function json_encode($data) {
		return Afun_json_encode($data);
	}
}


/*
	window.open ('page.html','newwindow','height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no')
各项参数 
其中yes/no也可使用1/0；pixel value为具体的数值，单位象素。 

参数 | 取值范围 | 说明 

alwaysLowered | yes/no | 指定窗口隐藏在所有窗口之后 
alwaysRaised | yes/no | 指定窗口悬浮在所有窗口之上 
depended | yes/no | 是否和父窗口同时关闭 
directories | yes/no | Nav2和3的目录栏是否可见 
height | pixel value | 窗口高度 
hotkeys | yes/no | 在没菜单栏的窗口中设安全退出热键 
innerHeight | pixel value | 窗口中文档的像素高度 
innerWidth | pixel value | 窗口中文档的像素宽度 
location | yes/no | 位置栏是否可见 
menubar | yes/no | 菜单栏是否可见 
outerHeight | pixel value | 设定窗口(包括装饰边框)的像素高度 
outerWidth | pixel value | 设定窗口(包括装饰边框)的像素宽度 
resizable | yes/no | 窗口大小是否可调整 
screenX | pixel value | 窗口距屏幕左边界的像素长度 
screenY | pixel value | 窗口距屏幕上边界的像素长度 
scrollbars | yes/no | 窗口是否可有滚动栏 
titlebar | yes/no | 窗口题目栏是否可见 
toolbar | yes/no | 窗口工具栏是否可见 
Width | pixel value | 窗口的像素宽度 
z-look | yes/no | 窗口被激活后是否浮在其它窗口之上
*/

?>